new Vue({
    el: '#app',
    data: {
        selectedBatch: '',
        selectedStatus: '',
        schoolName: '',
        currentPage: 1,
        pageSize: 10,
        totalPages: 1,
        totalItems: 0,
        showRejectModal: false,
        rejectReason: '',
        currentTeamId: null,
        teams: [
            ]
    },
    computed: {
        filteredTeams() {
            let result = [...this.teams];
            if (this.selectedBatch) {
                result = result.filter(team => team.batch.includes(this.selectedBatch));
            }
            if (this.selectedStatus) {
                result = result.filter(team => team.status === this.selectedStatus);
            }
            if (this.schoolName) {
                result = result.filter(team => team.highSchool.includes(this.schoolName));
            }
            this.totalItems = result.length;
            this.totalPages = Math.ceil(this.totalItems / this.pageSize);
            const startIndex = (this.currentPage - 1) * this.pageSize;
            return result.slice(startIndex, startIndex + this.pageSize);
        }
    },
    methods: {
        getStatusText(status) {
            switch(status) {
                case 'pending': return '待审核';
                case 'approved': return '审核通过';
                case 'rejected': return '审核驳回';
                default: return '';
            }
        },
        getStatusClass(status) {
            switch(status) {
                case 'pending': return 'status-pending';
                case 'approved': return 'status-approved';
                case 'rejected': return 'status-rejected';
                default: return '';
            }
        },
        search() {
            this.currentPage = 1;
        },
        resetFilter() {
            this.selectedBatch = '';
            this.selectedStatus = '';
            this.schoolName = '';
            this.currentPage = 1;
        },
        viewTeam(id) {
            alert(`查看ID为 ${id} 的队伍详情`);
        },
        approveTeam(id) {
            if(confirm('确定要通过该队伍的审核吗？')) {
                const team = this.teams.find(t => t.id === id);
                if(team) team.status = 'approved';
                alert('审核已通过');
            }
        },
        rejectTeam(id) {
            this.currentTeamId = id;
            this.rejectReason = '';
            this.showRejectModal = true;
        },
        confirmReject() {
            if(!this.rejectReason.trim()) {
                alert('请输入驳回原因');
                return;
            }
            const team = this.teams.find(t => t.id === this.currentTeamId);
            if(team) {
                team.status = 'rejected';
                alert('已驳回该队伍申请，原因：' + this.rejectReason);
                this.showRejectModal = false;
            }
        }
    },
    mounted() {
        this.totalItems = this.teams.length;
        this.totalPages = Math.ceil(this.totalItems / this.pageSize);
    }
});